package com.InetDemo.TCPDemo;

/*
* 发送数据
*   创建客户端的Socket对象（Socket）
    获取输出流，写数据
    释放资源
* */

import java.io.*;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class ClientDemo {
    public static void main(String[] args) throws IOException {
        //创建客户端的Socket对象
        Socket s = new Socket("192.168.3.37", 10000);

        //获取输出流，写数据
        OutputStream os = s.getOutputStream();
        os.write("hello".getBytes(StandardCharsets.UTF_8));

        //获取输入流，读数据
        InputStream is = s.getInputStream();
        byte[] bys = new byte[1024];
        int len = is.read(bys);
        String data = new String(bys, 0, len);
        System.out.println("客户端："+data);

        //释放资源
        s.close();

    }
}
